package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.*;
import com.itlong.cloud.POJO.PO.ProjectPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.*;
import com.itlong.cloud.POJO.VO.property.PropertyRoleProjectGetVO;
import com.itlong.cloud.POJO.VO.property.PropertyTreeMenuVO;
import com.itlong.cloud.operate.service.IOperateProjectService;
import com.itlong.cloud.project.operate.IOperateProjectServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      项目信息服务暴露接口实现类
 * </desc>
 *
 * @createDate 2017-10-10.
 */
@RestController
public class OperateProjectServiceResource implements IOperateProjectServiceClient {
    @Autowired
    IOperateProjectService iOperateProjectService;


    /**
     * <desc>
     * 判断项目存在性
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-27
     */
    @Override
    @RequestMapping(path = "/operate/project/exist", method = {RequestMethod.POST})
    public Integer checkProjectExist(@RequestParam(name = "projectId") String projectId) throws Exception {
        return iOperateProjectService.checkProjectExist(projectId);
    }

    /**
     * <desc>
     * 添加新项目
     * <desc/>
     *
     * @param saveDTO 新增项目信息
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-12
     */
    @Override
    @RequestMapping(path = "/operate/project/add", method = {RequestMethod.POST})
    public Integer saveProject(@RequestBody OperateProjectSaveDTO saveDTO) throws Exception {
        Integer result = iOperateProjectService.saveProject(saveDTO);
        return result;
    }

    /**
     * <desc>
     * 更新单个项目信息
     * <desc/>
     *
     * @param updateDTO 项目更新信息
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-11
     */
    @Override
    @RequestMapping(path = "/operate/project/update", method = {RequestMethod.POST})
    public Integer updateProject(@RequestBody OperateProjectUpdateDTO updateDTO) throws Exception {
        Integer result = iOperateProjectService.updateProject(updateDTO);
        return result;
    }

     /**
      * <desc>
      *      分页获取项目信息（简易信息）
      * <desc/>
      *
      * @param pageDTO 分页查询项目信息条件对象
      * @return
      * @author Chunjian.G
      * @createDate 2017-10-10
      */
    @Override
    @RequestMapping(path = "operate/project/getPage", method = {RequestMethod.POST})
    public Page<OperateProjectVO> getPage(@RequestBody OperateProjectGetPageDTO pageDTO) throws Exception{
        Page<OperateProjectVO> page = iOperateProjectService.getPage(pageDTO);
        return  page;
    }

    /**
     * <desc>
     * 获取单个项目详情
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-11
     */
    @Override
    @RequestMapping(path = "/operate/project/getDetail", method = {RequestMethod.POST})
    public OperateProjectDetailVO getDetail(@RequestParam(name = "projectId") String projectId) throws Exception{
        OperateProjectDetailVO detailVO = iOperateProjectService.getDetail(projectId);
        return detailVO;
    }

    /**
     * <desc>
     * 获取单个项目的关联设备
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/getProjectProduct", method = {RequestMethod.POST})
    public List<OperateProjectRelatedProductVO> getRelatedProducts(String projectId) throws Exception {
        List<OperateProjectRelatedProductVO> productVOS = iOperateProjectService.getRelatedProducts(projectId);
        return productVOS;
    }

    /**
     * <desc>
     * 更新单个项目的关联设备信息
     * <desc/>
     *
     * @param projectId 项目编号
     * @param saveDTOS  关联设备信息列表
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/updateProjectProduct", method = {RequestMethod.POST})
    public Integer saveRelatedProducts(@RequestParam(name = "projectId") String projectId,
                                       @RequestBody List<OperateProjectRelatedProductSaveDTO> saveDTOS) throws Exception {
        Integer result = iOperateProjectService.saveRelatedProducts(projectId, saveDTOS);
        return result;
    }

    /**
     * <desc>
     *      根据用户id查询关联的所有项目id及名称
     * </desc>
     *
     * @param userId 用户id
     * @return
     * @aurhor Jiaqi.X
     * @createDate 2017/10/11
     */
    @RequestMapping(path = "/operate/project/getEngineerProjectInfo")
    @Override
    public Map<String,Object> getEngineerProjectInfo(@RequestParam("userId")String userId){
        return iOperateProjectService.getEngineerProjectInfo(userId);
    }

    /**
     * <desc>
     *      获取所有项目信息，只取id及名称供下拉菜单使用
     * </desc>
     *
     * @return
     * @author Jiaqi.X
     * @craeteDate 2017/10/11
     */
    @RequestMapping(path = "/operate/project/getAllotProjectPage")
    @Override
    public Page<OperateAllotProjectVO> getAllotProjectPage(@RequestBody OperateAllotProjectDTO pageDTO) throws Exception {
        return iOperateProjectService.getAllotProjectPage(pageDTO);
    }

    /**
     * <desc>
     *      更改项目状态
     * <desc/>
     *
     * @param projectId 项目Id
     * @param status 项目状态，默认1，0-删除，1启用，2-禁用
     * @return
     * @author zhangs
     * @createDate 2017/10/31
     */
    @RequestMapping(path = "dockWith/manage/updateProjectStatus", method = RequestMethod.POST)
    @Override
    public void updateProjectStatus(@RequestParam("projectId")String projectId, @RequestParam("status")String status) throws Exception{
        iOperateProjectService.updateProjectStatus(projectId, status);
    }

    /**
     * <desc>
     *      是否启用云对讲。
     * <desc/>
     *
     * @param  projectId 项目编号
     * @return 0-禁用  1-启用
     * @author shengen.T
     * @createDate 2017-11-30
     */
    @Override
    @RequestMapping(path = "/operate/project/getIsSmartCommunity", method = RequestMethod.POST)
    public Integer getIsSmartCommunity(@RequestParam("projectId") String projectId) throws Exception{
        return iOperateProjectService.getIsSmartCommunity(projectId);
    }

    /**
     * <desc>
     *      是否启用云电梯和蓝牙电梯。
     * <desc/>
     *
     * @param  projectId 项目编号
     * @return 0-禁用  1-启用
     * @author Juguang.S
     * @createDate 2018-04-09
     */
    @Override
    @RequestMapping(path = "/operate/project/getIsCloudElevator", method = RequestMethod.POST)
    public Map<String,Integer> getIsCloudElevator(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getIsCloudElevator(projectId);
    }

    /**
     * <desc>
     * 获取项目状态：1-启用，2-禁用
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Chunjian.G
     * @createDate 2017-12-01
     */
    @Override
    @RequestMapping(path = "/operate/project/getProjectStatus", method = RequestMethod.POST)
    public Integer getProjectStatus(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getProjectStatus(projectId);
    }

    /**
     * <desc>
     * 单表-获取项目信息
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Chunjian.G
     * @createDate 2017-12-05
     */
    @Override
    @RequestMapping(path = "/operate/project/getOneProject", method = RequestMethod.POST)
    public ProjectPO getOneProject(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getOneProject(projectId);
    }

    /**
     * <desc>
     *      获取项目列表(项目ID+项目编号)。
     * <desc/>
     *
     * @param  projectName 项目编号
     * @return
     * @author shengen.T
     * @createDate 2018-01-12
     */
    @RequestMapping(path = "/operate/project/getProjectInfoList", method = RequestMethod.POST)
    public List<OperateProjectInfoVO> getProjectInfoList(@RequestParam("projectName") String projectName) throws Exception{
        return iOperateProjectService.getProjectInfoList(projectName);
    }

    /**
     * <desc>
     * 获取项目所在省份/自治区/直辖市名称.
     * </desc>
     *
     * @param projectId 项目Id
     * @return 所在省份/自治区/直辖市名称
     * @author LewisLouis
     * @createDate 2018-01-27
     */
    @Override
    @RequestMapping(path = "/operate/project/getProjectProvinceName", method = RequestMethod.POST)
    public String getProjectCityName(@RequestParam("projectId")String projectId) {
        return iOperateProjectService.getProjectCityName(projectId);
    }

    /**
     * <desc>
     *      判断项目云设备状态是否为启用
     * </desc>
     *
     * @param projectId 项目id
     * @param type  设备类型 1云对讲 2云电梯
     * @return
     * @author Jiaqi.X
     * @createDate 2018/04/24
     */
    @RequestMapping(path = "/operate/project/checkProjectCloudDeviceStatus", method = RequestMethod.POST)
    @Override
    public boolean checkProjectCloudDeviceStatus(@RequestParam("projectId") String projectId,@RequestParam("type") Integer type){
        return iOperateProjectService.checkProjectCloudDeviceStatus(projectId,type);
    }

    /**
     * <desc>
     *      获取用户权限和项目信息相关字段，用于云电梯SDK上报设备信息变更后接口数据结构说明
     * </desc>
     *
     * @param projectId 项目id
     * @return 获取用户项目信息VO
     * @author wangzhi
     * @createDate 2019/01/21
     */
    @Override
    @RequestMapping(path = "/operate/project/getRoleProjectInfo", method = RequestMethod.POST)
    public List<PropertyRoleProjectGetVO> getRoleProjectInfo(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getRoleProjectInfo(projectId);
    }

    /**
     * <desc>
     *      根据项目编号获取项目类型 住宅和办公。
     * <desc/>
     *
     * @param  projectId 项目编号
     * @return 项目类型
     * @author Juguang.S
     * @createDate 2019-08-14
     */
    @Override
    @RequestMapping(path = "/operate/project/getProjectType", method = RequestMethod.POST)
    public String getProjectType(@RequestParam("projectId") String projectId) throws Exception{
        return iOperateProjectService.getProjectType(projectId);
    }

    /**
     * <desc>
     *      查询项目信息及统计信息
     * </desc>
     *
     * @param
     * @return
     * @Author Zhu.yj
     * @createDate  2019/10/28
     */
    @Override
    @RequestMapping(path = "/operate/project/getPassTypePercent",method = RequestMethod.POST)
    public List<Map<String, Object>> getPassTypePercent() throws Exception {
        return iOperateProjectService.getPassTypePercent();
    }

    /**
     * <desc>
     *      查询城市项目占比排行
     * </desc>
     *
     * @param
     * @return
     * @Author Zhu.yj
     * @createDate  2019/10/31
     */
    @Override
    @RequestMapping(path = "operate/project/getCityProjectRank",method = RequestMethod.POST)
    public OperateProjectStatisticInfoVO getCityProjectRank() throws Exception {
        return iOperateProjectService.getCityProjectRank();
    }

    /**
     * <desc>
     * 获取可用最小项目编号值
     * </desc>
     *
     * @return
     * @Author caoshuai
     * @createDate 2020/09/16
     */
    @Override
    @RequestMapping(path = "operate/project/getMinProjectId", method = RequestMethod.POST)
    public String getMinProjectId() {
        return iOperateProjectService.getMinProjectId();
    }


    /**
     * <desc>
     * RobotGo调试工具获取项目下的开发者用户的 机器人设备授权状态和机器人白名单授权状态
     * </desc>
     *
     * @param projectId
     * @param userId
     * @Author chengshican
     * @Date 2020-09-17 17:00
     * @Param
     * @Return
     * @Exception
     */
    @Override
    @RequestMapping(path = "operate/project/getRobotGoProjectWhitelistAndDeviceAuthStatusByUserId",method = RequestMethod.POST)
    public Map<String, Object> getRobotGoProjectWhitelistAndDeviceAuthStatusByUserId(@RequestParam("projectId") String projectId,@RequestParam("userId") String userId) throws Exception {
        return iOperateProjectService.getRobotGoProjectWhitelistAndDeviceAuthStatusByUserId(projectId, userId);
    }

    /**
     * <desc>
     *      获取证书详情
     * </desc>
     *
     * @param operateLicenseDTO 查询参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/17
     */
    @Override
    @RequestMapping(path = "/operate/project/getLicenseDetail", method = RequestMethod.POST)
    public OperateLicenseAllInfoVO getLicenseDetail(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.getLicenseDetail(operateLicenseDTO);
    }

    /**
     * <desc>
     *      修改特征码状态
     * </desc>
     *
     * @param operateLicenseDTO 查询参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/17
     */
    @Override
    @RequestMapping(value = "/operate/project/updatePCStatus", method = RequestMethod.POST)
    public Integer updatePCStatus(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.updatePCStatus(operateLicenseDTO);
    }

    /**
     * <desc>
     *      获取日志分页列表
     * </desc>
     *
     * @param operateLicenseDTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/18
     */
    @Override
    @RequestMapping(value = "/operate/project/getLogPage", method = RequestMethod.POST)
    public Page<OperateProjectLogPageVO> getLogPage(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.getLogPage(operateLicenseDTO);
    }

    /**
     * <desc>
     *      保存电脑特征码
     * </desc>
     *
     * @param operateLicenseDTO 证书管理DTO
     * @return 受影响行数
     * @Author Zhu.yj
     * @createDate  2020/9/18
     */
    @Override
    @RequestMapping(value = "/operate/project/savePcInfo", method = RequestMethod.POST)
    public MessageVO savePcInfo(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.savePcInfo(operateLicenseDTO);
    }

    /**
     * <desc>
     *      获取证书
     * </desc>
     *
     * @param operateLicenseDTO 参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/24
     */
    @PostMapping("/operate/project/getCertificate")
    @Override
    public Map<String, Object> getCertificate(@RequestBody  OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.getCertificate(operateLicenseDTO);
    }

    /**
     * <desc>
     *      在线获取证书信息
     * </desc>
     *
     * @param operateLicenseDTO 证书管理DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/25
     */
    @Override
    @RequestMapping(value = "/operate/project/getLicense", method = RequestMethod.POST)
    public OperateOnlineLicenseInfoVO getLicense(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.getLicense(operateLicenseDTO);
    }

    /**
     * <desc>
     *      下载证书
     * </desc>
     *
     * @param operateLicenseDTO 证书管理DTO
     * @return 证书加密字符串
     * @Author Zhu.yj
     * @createDate  2020/9/27
     */
    @Override
    @PostMapping("/operate/project/online/licenseDownload")
    public Map<String, Object> licenseDownload(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.licenseDownload(operateLicenseDTO);
    }

    /**
     * <desc>
     *      获取特征码信息列表
     * </desc>
     *
     * @param operateLicenseDTO 证书管理DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/27
     */
    @PostMapping("/operate/project/getPcInfoList")
    @Override
    public List<String> getPcInfoList(@RequestBody OperateLicenseDTO operateLicenseDTO) throws Exception {
        return iOperateProjectService.getPcInfoList(operateLicenseDTO);
    }

    /**
     * <desc>
     *      同步项目与特征码对应记录表数据()
     * </desc>
     *
     * @Author Zhu.yj
     * @createDate  2020/10/13
     */
    @PostMapping("/operate/project/synchronizeData")
    @Override
    public Integer synchronizeData() throws Exception {
        return iOperateProjectService.synchronizeData();
    }

    @RequestMapping(path = "/operate/project/timeTaskDevicePassRecordLatestSave", method = RequestMethod.POST)
    public Object timeTaskDevicePassRecordLatestSave(String startTime1, String endTime1, String startTime2, String endTime2) {
        return iOperateProjectService.timeTaskDevicePassRecordLatestSave(startTime1, endTime1, startTime2, endTime2);
    }

    /**
     * <desc>
     *      获取用户角色组列表
     * </desc>
     *
     * @param projectId
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/19
     */
    @Override
    @PostMapping("/householeInfo/getUserRoleList")
    public List<Map<String, Object>> getUserRoleList(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getUserRoleList(projectId);
    }

    /**
     * <desc>
     *      获取项目下的楼栋、单元房间列表
     * </desc>
     *
     * @param projectId 项目id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/19
     */
    @Override
    @PostMapping("/househole/getBuildList")
    public List<PropertyTreeMenuVO> getBuildList(@RequestParam("projectId") String projectId) throws Exception {
        return iOperateProjectService.getBuildList(projectId);
    }
}
